// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) definits fieldsfirst ansi space safe 
// Source File Name:   Abandon.java

package jones.behavior;

import jones.SimpleRobotInterface;
import jones.ValueNotAvailableException;

// Referenced classes of package jones.behavior:
//            EscapeSequence, Behavior, Arbiter

public class Abandon
    implements Behavior
{

    private static final String NAME = "Abandon";
    private EscapeSequence escapeSequence = null;

    public Abandon()
    {
        escapeSequence = new EscapeSequence();
    }

    public Abandon(double backupTime, double spin, double random, double spinTime, double forwardTime)
    {
        escapeSequence = new EscapeSequence();
        setBackupTime(backupTime);
        setSpin(spin);
        setRandom(random);
        setForwardTime(forwardTime);
    }

    public String getName()
    {
        return "Abandon";
    }

    public double getRandom()
    {
        return escapeSequence.getRandom();
    }

    public void setRandom(double random)
    {
        escapeSequence.setRandom(random);
    }

    public double getBackupTime()
    {
        return escapeSequence.getBackupTime();
    }

    public void setBackupTime(double backupTime)
    {
        escapeSequence.setBackupTime(backupTime);
    }

    public double getSpin()
    {
        return escapeSequence.getSpin();
    }

    public void setSpin(double spin)
    {
        escapeSequence.setSpin(spin);
    }

    public double getForwardTime()
    {
        return escapeSequence.getForwardTime();
    }

    public void setForwardTime(double forwardTime)
    {
        escapeSequence.setForwardTime(forwardTime);
    }

    public void update(double time)
    {
        escapeSequence.update(time);
    }

    public void act(Arbiter arbiter)
    {
        SimpleRobotInterface robot = (SimpleRobotInterface)arbiter.getRobotInterface(((Behavior) (this)));
        try
        {
            if (robot.isPushing() && !isLightVisible(robot) || escapeSequence.isStarted())
                escapeSequence.run(robot);
        }
        catch (ValueNotAvailableException ex) { }
    }

    private boolean isLightVisible(SimpleRobotInterface robot)
        throws ValueNotAvailableException
    {
        return robot.getLeftPhoto() != 0 || robot.getRightPhoto() != 0;
    }

    public String toString()
    {
        return "Abandon: " + escapeSequence.getState();
    }
}
